package com.shop.shopserver.controller.user;

import com.shop.shopcommon.result.Result;

import com.shop.shoppojo.vo.GoodsDetailVO;

import com.shop.shoppojo.vo.HomeDataVO;
import com.shop.shopserver.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.shop.shopcommon.constant.MessageConstant.SUCCESS;

@RestController
@RequestMapping("/goods")
@Api(tags = "商品模块")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    /**
     * 商品详情页
     * @param goodsId
     * @return
     */
    @GetMapping("/detail")
    @ApiOperation(value = "商品详情页")
    public Result<GoodsDetailVO> getGoodsDetail(@RequestParam Long goodsId){
        GoodsDetailVO goodsDetailVO = goodsService.getGoodsDetailByGoodsId(goodsId);
        return Result.success(goodsDetailVO,SUCCESS);

    }

    /**
     * 首页数据
     */
    @GetMapping("/page/getHomeData")
    @ApiOperation(value = "获取首页数据")
    public Result<HomeDataVO> getHomeData() throws Exception {
        HomeDataVO homeDataVO=goodsService.getHomeData();
        return Result.success(homeDataVO,SUCCESS);
    }

}
